package com.cqw.commontest;

import com.cqw.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-15 15:26
 * @Description:
 */
public class Test1 {

    @Autowired
    private KafkaTemplate kafkaTemplate;


    public static void main(String[] args) {
       /* DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar=Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY,-24);
        String yesterdayDate=dateFormat.format(calendar.getTime());
        //System.out.println(yesterdayDate);

        int i = 19/4;
        //System.out.println(i);

        String key = "hd:lottery_%s_%s";

        String format = String.format(key, null, "4");
        System.out.println(format);*/

        //@Data 重写了equals方法
        /*SysUser user = new SysUser(1, "张三", "123456", "男", "上海市");
        SysUser user1 = new SysUser(1, "张三", "123456", "男", "上海市");*/

        SysUser user = new SysUser();
        SysUser user1 = new SysUser();
        System.out.println(user.equals(user1));


        //将字符串反转
        String a = "abcdefg1";
        StringBuffer stringBuffer = new StringBuffer();     //线程安全
        stringBuffer.append(a);
        //System.out.println(stringBuffer.reverse());

        StringBuilder stringBuilder = new StringBuilder();  //非线程安全
        stringBuilder.append(a);
        //System.out.println(stringBuilder.reverse());

        byte[] bytes = a.getBytes(StandardCharsets.UTF_8);
        //System.out.println(Arrays.toString(bytes));


        List<SysUser> users = new ArrayList<>();
        users.add(user);
        users.add(user1);
        //Map<Integer, User> collect = users.stream().collect(Collectors.toMap(User::getUserid, Function.identity()));

        Map<Long, List<SysUser>> collect1 = users.stream().collect(Collectors.groupingBy(SysUser::getUserId));



        /*for (Integer integer : collect1.keySet()) {
            System.out.println(integer + "======" + collect1.get(integer));
        }*/

        List<String> list1 = new ArrayList<>();
        list1.add("q1");
        list1.add("q2");
        list1.add("q3");
        List<String> list2 = new ArrayList<>();
        list2.add("q1");
        list2.add("q2");
        list2.add("q3");
        list2.add("q4");
        list2.add("q5");
        //list1与list2做交集，结果集复制给list1，如果list1改变返回true，没有改变返回false
        boolean b = list1.retainAll(list2);
        System.out.println(b);
        System.out.println(list1);
        System.out.println(list2);




    }

}
